package LeetCode;

public class LeetCodeMain36 {
    public int count=0;
    public int minCameraCover(TreeNode root) {
        if (tan(root)==0){
            count++;
        }
        return count;
    }
    public int tan(TreeNode root){
        if (root==null){
            return 2;
        }
        int left=tan(root.left);
        int right=tan(root.right);
        if (left==2&&right==2){
            return 0;
        }
        if (left==0||right==0){
            count++;
            return 1;
        }
        if (left==1||right==1){
            return 2;
        }
        return -1;
    }
    public int jump(int[] nums) {
        if(nums.length==1){
            return 0;
        }
        int lastDistance=0;
        int newDistance=0;
        int res=0;
        for (int i = 0; i < nums.length; i++) {
            newDistance=Math.max(newDistance,nums[i]+i);
            if (i==lastDistance){
                if (lastDistance!=nums.length-1){

                    res++;
                    lastDistance=newDistance;
                    if (lastDistance>=nums.length){
                        break;
                    }
                }else {
                    break;
                }
            }
        }
        return res;
    }
}
